package com.example.demo.service.impl;

import com.example.demo.dao.BookNameDao;
import com.example.demo.dao.BookPressDao;
import com.example.demo.pojo.BookNameBean;
import com.example.demo.service.BookNameService;
import com.example.demo.service.BookPressService;
import com.example.demo.tools.BookNameSort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @Classname BookNameService
 * @Description TODO
 * @Date 2020/12/27 21:03
 * @Created by 新
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BookNameServiceImpl implements BookNameService {
    @Autowired
    BookNameDao bookNameDao;
    @Autowired
    BookPressDao bookPressDao;
    @Autowired
    BookPressServiceImpl bookPressService;

    @Override
    public List<BookNameBean> getBookNameList(String bookNameCon) {
        List<BookNameBean> bookList = bookNameDao.getBookList(bookNameCon);
        Collections.sort(bookList, new BookNameSort());
        return bookList;

    }

    public List<BookNameBean> getBookListDeDuplication(String bookNameCon) {
        List<BookNameBean> bookList = bookNameDao.getBookList(bookNameCon);
        Set<BookNameBean> set = new HashSet<BookNameBean>(bookList);
        List<BookNameBean> tempList = new ArrayList<BookNameBean>(set);
        return tempList;

    }

    @Override
    public HashMap deleteBookNameList(String bookName, String bookPress) {
        int k=bookNameDao.deleteBookNameList(bookName);
        int j= bookPressService.deleteBookPressList(bookPress);
        HashMap<String,Integer>  map   = new HashMap<>();
        map.put("bookNameList",k);
        map.put("bookPressList",j);
        return map;
    }
    @Override
    public int addBookNameList(List<String> bookNameList) {
        System.out.println("======>" + bookNameList);
        return bookNameDao.addBookNameList(bookNameList);
    }

    @Override
    public int updateBookNameList(String bookName,String bookNameCon) {
        return bookNameDao.updateBookList( bookName, bookNameCon);
    }
}
